package personal.lijun.skeleton.web.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.web.bind.annotation.*;
import personal.lijun.skeleton.springcloud.common.data.ApiResultListSet;
import personal.lijun.skeleton.springcloud.common.data.ApiResultPrimitiveValue;

/**
 * @Auther: lijun@sstcsoft.com
 * @Date: 2019/9/12 10:50
 */
@FeignClient( name = "${service.provider.name}")
public interface CalendarServiceFeign {
    @RequestMapping(method ={RequestMethod.GET}, value = "/user/getUser")
    CalendarUser getUser(@RequestParam("id") long id);

    @RequestMapping(value = "/user/findUserByEmail", method = {RequestMethod.GET})
    CalendarUser findUserByEmail(@RequestParam("email")String email);

    @RequestMapping(value = "/user/findUsersByPartialEmail", method = {RequestMethod.GET})
    ApiResultListSet<CalendarUser> findUsersByPartialEmail(@RequestParam("email")String email);

    @RequestMapping(value = "/user/addNew", method = {RequestMethod.POST})
    CalendarUser createUser(@RequestBody CalendarUser user);

    @RequestMapping(value = "/user/deleteUsersById", method = {RequestMethod.POST})
    ApiResultPrimitiveValue<Integer> deleteCalendarUsersById(@RequestParam("id")Long id);

    /**
     * 查询指定id的用户事件信息
     * @param id 用户事件id
     * @return
     */
    @PostAuthorize("hasRole('ROLE_ADMIN') or " +
            "principal.id == returnObject.owner or " +
            "principal.id == returnObject.attendee")
    @RequestMapping(value = "/event/getEventsById",method = {RequestMethod.GET})
    Event  getEvent(@RequestParam("id")Long id);

    /**
     * 查询指定用户的事件
     *
     * @param userId 用户id
     * @return 事件列表
     */
    @RequestMapping(value = "/event/findForUser",method = {RequestMethod.GET})
    ApiResultListSet<Event> findForUser(@RequestParam("userId")Long userId);

    /**
     * 增加一个新用户事件
     * @param event
     * @return
     */
    @RequestMapping(value = "/event/addNewEvents",method = {RequestMethod.POST})
    Event createEvent(@RequestBody Event event);

    /**
     * 根据id删除指定用户事件
     * @param id 用户事件id
     * @return
     */
    @RequestMapping(value = "/event/deleteEventsById",method = {RequestMethod.POST})
    ApiResultPrimitiveValue<Integer>  deleteEventsById(@RequestParam("id") Long id);

    /**
     * 获取所有的事件
     * @return
     */
    @RequestMapping(value = "/event/getEvents",method = {RequestMethod.GET})
    ApiResultListSet<Event> getEvents();

    /**
     * 查询指定用户的角色信息
     * @param userId 用户Id
     * @return
     */
    @RequestMapping(value = "user/findUserRoles", method = {RequestMethod.GET})
     ApiResultListSet<Role> findUserRoles(@RequestParam("userId") Long userId);
}
